package com.tianji.promotion.mapper;

import com.tianji.promotion.domain.po.ExchangeCode;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tianji.promotion.enums.ExchangeCodeStatus;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 兑换码 Mapper 接口
 * </p>
 *
 * @author xzh
 * @since 2024-03-20
 */
public interface ExchangeCodeMapper extends BaseMapper<ExchangeCode> {

    /**
     * 修改兑换码状态为已使用 添加使用人 乐观锁:status=#{oldStatus}
     * @param userId
     * @param status
     * @param serialNum
     */
    @Update("update exchange_code set user_id=#{userId},status=#{stasus} " +
            "where id=#{serialNum} and status=#{oldStatus}")
    static void happyLockUpdateCodeById(@Param("userId") Long userId,
                                        @Param("status") ExchangeCodeStatus status,
                                        @Param("oldStatus") ExchangeCodeStatus oldStatus,
                                        @Param("serialNum") long serialNum) {
    }
}
